# words/serializers.py

from rest_framework import serializers
from .models import (
    Noun, Verb, Adjective, Other, VerbConjugation,
)

class VerbConjugationSerializer(serializers.ModelSerializer):
    class Meta:
        model = VerbConjugation
        fields = ['form_type', 'person', 'conjugated_form']


class VerbSerializer(serializers.ModelSerializer):
    conjugations = VerbConjugationSerializer(many=True, read_only=True)
    base_form = serializers.SerializerMethodField()

    class Meta:
        model = Verb
        fields = [
            'word', 'sentence', 'chinese', 'chinese_sentence', 'level',
            'stark', 'divisible', 'reflexive', 'auxiliary',
            'p1', 'p2', 'conjugations',
            'base_form',
        ]

    def get_base_form(self, obj):
        return obj.word  # 如果需要不同逻辑，请修改


class NounSerializer(serializers.ModelSerializer):
    class Meta:
        model = Noun
        fields = '__all__'


class AdjectiveSerializer(serializers.ModelSerializer):
    class Meta:
        model = Adjective
        fields = '__all__'


class OtherSerializer(serializers.ModelSerializer):
    class Meta:
        model = Other
        fields = '__all__'




class WordDetailSerializer(serializers.Serializer):
    noun = NounSerializer(required=False)
    verb = VerbSerializer(required=False)
    adjective = AdjectiveSerializer(required=False)
    other = OtherSerializer(required=False)

class SynonymResponseSerializer(serializers.Serializer):
    lemma = serializers.CharField()
    synonyms = serializers.ListField(child=serializers.CharField())
    phrases = serializers.ListField(child=serializers.CharField())
